/*
Replication Do File for Main Results:

Hye Ryeon Jang and Benjamin Smith (2021) "Pax Petrolica? 
	Rethinking the Oil-Interstate War Linkage"

Data generated using Stata 16 
*/ 

********************************************************************************
***        TABLE 1. Colgan Analysis with Iran-Iraq War Variable.             ***
***                 Timespan: 1945-2001 for all models.                      ***
********************************************************************************

use "Colgan_with_IIW.dta", clear

eststo clear

eststo, ti(Model 1): xtpoisson revonsets radicalleader oil_state radoil /// 
ln_gdp_combo ln_pop polity borders coldwar muslim major i.regnum ///
py1-py4 if revonsets<10

eststo, ti(Model 2): xtpoisson revonsets radicalleader oil_state radoil ///
ln_gdp_combo ln_pop polity coldwar borders py1-py4 if revonsets<10, fe

eststo, ti(Model 3): xtpoisson revonsets radicalleader oil_state radoil ///
i.iraniraq88 ln_gdp_combo ln_pop polity borders coldwar muslim major ///
i.regnum py1-py4 if revonsets<10 

eststo, ti(Model 4): xtpoisson revonsets radicalleader oil_state radoil ///
i.iraniraq88 ln_gdp_combo ln_pop polity coldwar borders ///
py1-py4 if revonsets<10, fe

estout _all, ///
	cells(b(star fmt(3)) se(par(`"="("'`")""'))) ///
	stats(N aic bic, labels(Observations AIC BIC)) ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label varlabels(_cons Constant) ///
	legend ti("Table 1: Colgan Analysis with Iran-Iraq War Variable")


********************************************************************************
***     TABLE 2. Hendrix Oil Price Analysis with Iran-Iraq War Variable.     ***
*** 			 Timespan: 1947-2001.                                        ***
********************************************************************************

use "Hendrix_Monadic_with_IIW.dta", clear

eststo clear

eststo, ti(Model 5): nbreg f.revonsets realoil_08 radicalleader ///
realoil_revleader_update oil_state revleader_oilstate realoil_oilstate_update ///
realoil_revleader_oilstate iraniraq88 majorpower coldwar ln_pop ln_gdp_combo ///
polity peaceyears peaceyears_2 peaceyears_3 country_dummy* , cluster(ccode)

eststo, ti(Model 6): poisson f.revonsets realoil_08 radicalleader ///
realoil_revleader_update oil_state revleader_oilstate ///
realoil_oilstate_update realoil_revleader_oilstate iraniraq88 majorpower ///
coldwar ln_pop ln_gdp_combo polity peaceyears peaceyears_2 peaceyears_3 ///
country_dummy* , cluster(ccode)

eststo, ti(Model 7): nbreg f.revonsets realoil_08 radicalleader ///
realoil_revleader_update oil_state revleader_oilstate ///
realoil_oilstate_update realoil_revleader_oilstate iraniraq88 majorpower ///
coldwar ln_pop ln_gdp_combo polity peaceyears peaceyears_2 ///
peaceyears_3 , cluster(ccode)

eststo, ti(Model 8): poisson f.revonsets realoil_08 radicalleader ///
realoil_revleader_update oil_state revleader_oilstate ///
realoil_oilstate_update realoil_revleader_oilstate iraniraq88 majorpower ///
coldwar ln_pop ln_gdp_combo polity  peaceyears peaceyears_2 /// 
peaceyears_3 , cluster(ccode)

estout _all, ///
	cells(b(star fmt(3)) se(par(`"="("'`")""'))) ///
	stats(N aic bic, labels(Observations AIC BIC)) ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label varlabels(_cons Constant) ///
	legend ti("Table 2: Hendrix Oil Price Analysis with Iran-Iraq War Variable")
	

********************************************************************************
***     TABLE 3. Oil-War Models with Petrostate and Oil Income Measures.     ***
***              Time span: 1945-2010 for All Models.						 ***
********************************************************************************

use "PaxPetrolica_Main.dta", clear

eststo clear

eststo, ti(Model 9): xtpoisson revonsets i.revolutionaryleader ///
i.new_oil_state i.revolutionaryleader#i.new_oil_state ln_gdppc lnpop polity ///
borders coldwar muslim major i.regnum peaceyearsp1-peaceyearsp3 if revonsets<10

eststo, ti(Model 10): xtpoisson revonsets i.revolutionaryleader ///
i.new_oil_state i.revolutionaryleader#i.new_oil_state iraniraq88 ln_gdppc ///
lnpop polity borders coldwar muslim major i.regnum ///
peaceyearsp1-peaceyearsp3 if revonsets<10

eststo, ti(Model 11): xtpoisson revonsets i.revolutionaryleader c.logoil ///
i.revolutionaryleader#c.logoil ln_gdppc lnpop polity borders ///
coldwar muslim major i.regnum peaceyearsp1-peaceyearsp3 if revonsets<10 

eststo, ti(Model 12): xtpoisson revonsets i.revolutionaryleader c.logoil ///
i.revolutionaryleader#c.logoil iraniraq88 ln_gdppc lnpop polity borders ///
coldwar muslim major i.regnum peaceyearsp1-peaceyearsp3 if revonsets<10 

estout _all, ///
	cells(b(star fmt(3)) se(par(`"="("'`")""'))) ///
	stats(N aic bic, labels(Observations AIC BIC)) ///
	starlevels(* 0.10 ** 0.05 *** 0.01) label varlabels(_cons Constant) ///
	legend ti("Table 3: Oil-War Models with Petrostate and Oil Income Measures")

	
********************************************************************************
*** FIGURE 1.1. Effect of Oil and Gas Income per capita on MIDs (Model 11)   ***
***				Full Time Span (1945-2010) 									 ***
********************************************************************************

xtpoisson revonsets i.revolutionaryleader c.logoil ///
i.revolutionaryleader#c.logoil ln_gdppc lnpop polity borders ///
coldwar muslim major i.regnum peaceyearsp1-peaceyearsp3 if revonsets<10 

margins, at(logoil=(-7(2)12)) atmeans
marginsplot, ytitle(Expected Logged Counts of MIDs per year) ///
xtitle(Logged Oil & Gas Income per capita) xlabel(-7(2)12)


********************************************************************************
***  FIGURE 1.2. Effect of Oil and Gas Income per capita on MIDs             ***
*** 			 by Revolutionary Leaders  (Model 11)                        ***
***				 Full Time Span (1945-2010) 								 ***
********************************************************************************

xtpoisson revonsets i.revolutionaryleader c.logoil ///
i.revolutionaryleader#c.logoil ln_gdppc lnpop polity borders ///
coldwar muslim major i.regnum peaceyearsp1-peaceyearsp3 if revonsets<10 

margins revolutionaryleader, at(logoil=(-7(2)12)) atmeans
marginsplot, recast(line) recastci(rarea) ///
ytitle(Expected Logged Counts of MIDs per year) ///
xtitle(Logged Oil & Gas Income per capita) xlabel(-7(2)12)


********************************************************************************
***  FIGURE 1.3. Effect of Oil and Gas Income per capita on MIDs             ***
*** 			 by Revolutionary Leaders  (Model 12)                        ***
***				 Full Time Span (1945-2010) 								 ***
********************************************************************************

xtpoisson revonsets i.revolutionaryleader c.logoil ///
i.revolutionaryleader#c.logoil iraniraq88 ln_gdppc lnpop polity borders ///
coldwar muslim major i.regnum peaceyearsp1-peaceyearsp3 if revonsets<10 

margins revolutionaryleader, at(logoil=(-7(2)12)) atmeans
marginsplot, recast(line) recastci(rarea) ///
ytitle(Expected Logged Counts of MIDs per year) ///
xtitle(Logged Oil & Gas Income per capita) xlabel(-7(2)12)


********************************************************************************
***         FIGURE 2. Studentized Pearson Residuals                          ***
***                   for Iran-Iraq War years (Model 10)                     ***
********************************************************************************

glm revonsets i.revolutionaryleader i.new_oil_state ///
i.revolutionaryleader#i.new_oil_state ln_gdppc lnpop polity borders ///
coldwar muslim major iraniraq88 i.regnum peaceyearsp1-peaceyearsp3  ///
if revonsets<10, family(poisson) link(log) cluster(ccode)

predict fitted_g
predict res_pg, pearson studentized
separate res_pg, by(iraniraq88) 

two scatter res_pg0 res_pg1 fitted, ytitle("Studentized Pearson Residuals") ///
xtitle("Predicted Mean Counts of MIDs per Year") legend(rows(3)) ///
legend(ring(0) position(5)) scheme(s1mono)

